package com.ruicar.afs.cloud.risk.tortoise.dto.response;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumDeserializer;
import com.ruicar.afs.cloud.common.core.enums.AfsEnumSerializer;
import com.ruicar.afs.cloud.risk.tortoise.enums.GwtTortoiseRespStatus;
import lombok.*;

import java.io.Serializable;


/**
 * @Description
 * @Author Peng Jinbo
 * @Date 2020/07/29 14:06
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class GwtTortoiseResponse<T> implements Serializable {

    /**
     * Status
     */
    @JSONField(name = "success",serializeUsing = AfsEnumSerializer.class, deserializeUsing = AfsEnumDeserializer.class)
    @JsonProperty("success")
    @JsonSerialize( using = AfsEnumSerializer.class)
    @JsonDeserialize(using = AfsEnumDeserializer.class )
    private GwtTortoiseRespStatus status;

    /**
     * Message
     */
    @JSONField(name = "message")
    @JsonProperty("message")
    private String message;

    /**
     * Code
     */
    @JSONField(name = "code")
    @JsonProperty("code")
    private String code;

    /**
     * Data
     */
    @JsonInclude
    @JSONField(name = "data")
    @JsonProperty("data")
    private T data;

    /**
     * Author Peng Jinbo
     * Success gwt tortoise response
     *
     * @return the gwt tortoise response
     */
    public static GwtTortoiseResponse success(){
        return success("DEFAULT "+GwtTortoiseRespStatus.SUCCESS.name());
    }

    /**
     * Author Peng Jinbo
     * Success gwt tortoise response
     *
     * @param message message
     * @return the gwt tortoise response
     */
    public static GwtTortoiseResponse success(String message){
        return GwtTortoiseResponse.builder()
                .status(GwtTortoiseRespStatus.SUCCESS)
                .code(GwtTortoiseRespStatus.SUCCESS.name())
                .message(message).build();
    }

    /**
     * Author Peng Jinbo
     * Err gwt tortoise response
     *
     * @return the gwt tortoise response
     */
    public static GwtTortoiseResponse err(){
        return err("DEFAULT " + GwtTortoiseRespStatus.ERROR.name());
    }

    /**
     * Author Peng Jinbo
     * Err gwt tortoise response
     *
     * @param message message
     * @return the gwt tortoise response
     */
    public static GwtTortoiseResponse err(String message){
        return GwtTortoiseResponse.builder()
                .status(GwtTortoiseRespStatus.ERROR)
                .code(GwtTortoiseRespStatus.ERROR.name())
                .message(message).build();
    }

    /**
     * Author Peng Jinbo
     * Success data gwt tortoise response
     *
     * @param data data
     * @return the gwt tortoise response
     */
    public static GwtTortoiseResponse successData(Object data){
        GwtTortoiseResponse response = success();
        response.setData(data);
        return response;
    }

}
